home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINFONTS / FNTPRN.ZIP / FNTSRC.ZIP / FNTPRN.C < prev    next >
Text File  |  1993-03-16  |  16KB  |  357 lines

  1. // Contents copyright (c) 1993 John Deurbrouck
  2. /*
  3. **  Includes
  4. */
  5. #include<windows.h>
  6. #include<commdlg.h>
  7. #include<stdlib.h>
  8. #include<ctype.h>
  9. #include<string.h>
  10. #include"controls.h"
  11. #include"enumfont.h"
  12.  
  13. /*
  14. **  Defines
  15. */
  16. #define IDD_GETGOING 200
  17. #define IDM_ABOUT 1
  18. #define IDM_HELP 2
  19.  
  20. /*
  21. **  Global Variables
  22. */
  23. int OldLfHeight;
  24. HCURSOR hHourGlass;                     // global so call LoadCursor() just once
  25.  
  26. /*
  27. **  Function Prototypes
  28. */
  29. long FAR PASCAL _export WndProc(HWND,UINT,UINT,LONG);
  30. static void show_default_text_settings(HWND hwndDesc);
  31.  
  32. /*
  33. **  Function Definitions
  34. */
  35. #pragma argsused
  36. int PASCAL WinMain(HANDLE hInstance,HANDLE hPrevInstance,LPSTR lpszCmdLine,int nCmdShow){
  37.     MSG msg;
  38.     HWND hwnd;
  39.     WNDCLASS wndclass;
  40.     static LPSTR appname="FntPrn";
  41.     instance=hInstance;
  42.     hHourGlass=LoadCursor(NULL,IDC_WAIT);
  43.     // verify we're in Win 3.1 or better
  44.     {
  45.         DWORD dwVersion=GetVersion();
  46.         unsigned int winver=((unsigned int)LOBYTE(LOWORD(dwVersion)))<<8;
  47.         winver|=(unsigned int)HIBYTE(LOWORD(dwVersion));
  48.         if(winver<0x30A){
  49.             MessageBox(NULL,"FntPrn requires Windows 3.1 or later",
  50.              "ERROR",MB_OK|MB_ICONSTOP);
  51.             return 1;
  52.         }
  53.     }
  54.     if(!hPrevInstance){
  55.         wndclass.style=CS_HREDRAW|CS_VREDRAW;
  56.         wndclass.lpfnWndProc=WndProc;
  57.         wndclass.cbClsExtra=0;
  58.         wndclass.cbWndExtra=DLGWINDOWEXTRA;
  59.         wndclass.hInstance=hInstance;
  60.         wndclass.hIcon=LoadIcon(hInstance,"FntPrn2");
  61.         wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
  62.         wndclass.hbrBackground=COLOR_WINDOW+1;
  63.         wndclass.lpszMenuName=NULL;
  64.         wndclass.lpszClassName=appname;
  65.         RegisterClass(&wndclass);
  66.     }
  67.     hwnd=CreateDialog(hInstance,appname,0,NULL);
  68.     if(!hwnd){
  69.         MessageBox(NULL,"Could not create window","ERROR",MB_OK|MB_ICONSTOP);
  70.         return 1;
  71.     }
  72.     hwndDialog=hwnd;
  73.     // add new options to System Menu
  74.     {
  75.         HMENU hMenu;
  76.         hMenu=GetSystemMenu(hwnd,FALSE);
  77.         if(hMenu!=NULL){
  78.             EnableMenuItem(hMenu,SC_MAXIMIZE,MF_BYCOMMAND|MF_GRAYED);
  79.             EnableMenuItem(hMenu,SC_SIZE,MF_BYCOMMAND|MF_GRAYED);
  80.             AppendMenu(hMenu,MF_SEPARATOR,0,NULL);
  81.             AppendMenu(hMenu,MF_STRING,IDM_ABOUT,"&About...");
  82.             AppendMenu(hMenu,MF_STRING,IDM_HELP,"&Help...");
  83.         }
  84.     }
  85.     // get dialog box initialized
  86.     PostMessage(hwnd,WM_COMMAND,IDD_GETGOING,0L);
  87.     ShowWindow(hwnd,nCmdShow);
  88.     while(GetMessage(&msg,NULL,0,0)){
  89.         // next line intercepts ESC key so IsDialogMessage() can't exit on it
  90.         if((msg.message==WM_KEYDOWN&&msg.wParam==VK_ESCAPE)||(!IsDialogMessage(hwnd,&msg))){
  91.             TranslateMessage (&msg) ;
  92.             DispatchMessage (&msg) ;
  93.         }
  94.     }
  95.     return msg.wParam ;
  96. }
  97.  
  98. // this is a dialog box procedure but is also the main window
  99. long FAR PASCAL _export WndProc(HWND hwnd,UINT message,UINT wParam,LONG lParam){
  100.     static HWND hwndSampletext,hwndJustification,hwndSize,hwndDesc;
  101.     HCURSOR hSaveCursor;
  102.     switch(message){
  103.     case WM_KEYDOWN:
  104.         if(wParam==VK_ESCAPE)return 1;
  105.         break;
  106.     case WM_SYSCOMMAND:
  107.         switch(wParam){
  108.         case IDM_ABOUT:
  109.             MessageBox(hwndDialog,
  110.             "FntPrn 1.0\n"
  111.             "Font Printing Utility\n"
  112.             "Copyright ⌐ 1993 John Deurbrouck\n\n"
  113.             "First Published in PC Magazine April 13, 1993",
  114.             "FontPrint",MB_OK);
  115.             SetFocus(hwndSortorder);
  116.             return 1;
  117.         case IDM_HELP:
  118.             MessageBox(hwndDialog,
  119.             "FntPrn helps you browse your fonts.\n\n"
  120.             "You choose which fonts to see and how to sort them (Fonts section), "
  121.             "what you want to see in each font (Sample Text section), "
  122.             "and how you want the font names to look (Description Formatting section).\n\n"
  123.             "FntPrn creates a file (FNTPRN.WRI by default) "
  124.             "and optionally starts Write so you can browse or print the report.\n\n"
  125.             "See PC Magazine, April 13, 1993 (Vol. 12 No. 7) for more details.",
  126.             "FontPrint Help",MB_OK);
  127.             SetFocus(hwndSortorder);
  128.             return 1;
  129.         }
  130.         break;
  131.     case WM_COMMAND:
  132.         switch(wParam){
  133.         case IDD_GETGOING:
  134.             // do this instead of WM_INITDIALOG since child windows
  135.             // won't have been created by that time
  136.             hwndSortorder=GetDlgItem(hwnd,IDD_SORTORDER);
  137.             SendMessage(hwndSortorder,CB_INSERTSTRING,0,(LONG)(LPSTR)"Alphabetical");
  138.             SendMessage(hwndSortorder,CB_INSERTSTRING,1,(LONG)(LPSTR)"Height");
  139.             SendMessage(hwndSortorder,CB_INSERTSTRING,2,(LONG)(LPSTR)"Width");
  140.             SendMessage(hwndSortorder,CB_INSERTSTRING,3,(LONG)(LPSTR)"Proportion (Height/Width)");
  141.             SendMessage(hwndSortorder,CB_INSERTSTRING,4,(LONG)(LPSTR)"Weight");
  142.             SendMessage(hwndSortorder,CB_INSERTSTRING,5,(LONG)(LPSTR)"Font Family");
  143.             hwndSampletext=GetDlgItem(hwnd,IDD_SAMPLETEXT);
  144.             SendMessage(hwndSampletext,CB_INSERTSTRING,0,(LONG)(LPSTR)"\"AENOPS abefglmoqsty 801\"");
  145.             SendMessage(hwndSampletext,CB_INSERTSTRING,1,(LONG)(LPSTR)"Text Paragraph");
  146.             SendMessage(hwndSampletext,CB_INSERTSTRING,2,(LONG)(LPSTR)"Alphabet");
  147.             SendMessage(hwndSampletext,CB_INSERTSTRING,3,(LONG)(LPSTR)"\"Sample Text\"");
  148.             hwndJustification=GetDlgItem(hwnd,IDD_JUSTIFICATION);
  149.             SendMessage(hwndJustification,CB_INSERTSTRING,0,(LONG)(LPSTR)"Justified");
  150.             SendMessage(hwndJustification,CB_INSERTSTRING,1,(LONG)(LPSTR)"Left");
  151.             SendMessage(hwndJustification,CB_INSERTSTRING,2,(LONG)(LPSTR)"Center");
  152.             SendMessage(hwndJustification,CB_INSERTSTRING,3,(LONG)(LPSTR)"Right");
  153.             hwndSize=GetDlgItem(hwnd,IDD_SIZE);
  154.             hwndDesc=GetDlgItem(hwnd,IDD_SHOWDESCRIPTION);
  155.             // fall through to set defaults...
  156.         case IDD_DEFAULTS:
  157.             SendMessage(hwndSortorder,CB_SETCURSEL,0,0L);
  158.             SendMessage(hwndSampletext,CB_SETCURSEL,0,0L);
  159.             SendMessage(hwndJustification,CB_SETCURSEL,1,0L);
  160.             CheckRadioButton(hwnd,IDD_PITCHBOTH,IDD_PITCHVARIABLE,IDD_PITCHBOTH);
  161.             CheckRadioButton(hwnd,IDD_DEVICEPRINTER,IDD_DEVICESCREEN,IDD_DEVICEPRINTER);
  162.             CheckDlgButton(hwnd,IDD_SYNTHESIS,1);
  163.             CheckDlgButton(hwnd,IDD_TRUETYPEONLY,0);
  164.             CheckDlgButton(hwnd,IDD_NOVELTY,1);
  165.             CheckDlgButton(hwnd,IDD_MODERN,1);
  166.             CheckDlgButton(hwnd,IDD_ROMAN,1);
  167.             CheckDlgButton(hwnd,IDD_SANSSERIF,1);
  168.             CheckDlgButton(hwnd,IDD_SCRIPT,1);
  169.             CheckDlgButton(hwnd,IDD_OTHERFONTS,1);
  170.             CheckDlgButton(hwnd,IDD_REGULAR,1);
  171.             CheckDlgButton(hwnd,IDD_ITALIC,1);
  172.             CheckDlgButton(hwnd,IDD_BOLD,1);
  173.             CheckDlgButton(hwnd,IDD_BOLDITALIC,1);
  174.             CheckDlgButton(hwnd,IDD_LAUNCHWRITE,1);
  175.             SendMessage(hwndSize,WM_SETTEXT,0,(LONG)(LPSTR)"18");
  176.             default_font="Arial";
  177.             default_ffid=FF_SWISS;
  178.             default_pointsize=16;
  179.             default_just=JUST_LEFT;
  180.             default_bolditalic=0;
  181.             {                           // adjust points to logical units
  182.                 HDC hdc=CreateIC("DISPLAY",NULL,NULL,NULL);
  183.                 if(hdc==NULL)OldLfHeight=10;
  184.                 else{
  185.                     OldLfHeight=MulDiv(-(default_pointsize/2),
  186.                      GetDeviceCaps(hdc,LOGPIXELSY),72);
  187.                     DeleteDC(hdc);
  188.                 }
  189.             }
  190.             show_default_text_settings(hwndDesc);
  191.             SetFocus(hwndSortorder);
  192.             return 1;
  193.         case IDOK:                      // make the file
  194.             for(;;){
  195.                 SetCapture(hwnd);
  196.                 if(hHourGlass!=NULL)hSaveCursor=SetCursor(hHourGlass);
  197.                 switch(SendMessage(hwndSortorder,CB_GETCURSEL,0,0L)){
  198.                 default:
  199.